package io;

import java.util.zip.ZipInputStream;
import java.util.zip.ZipEntry;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.json.simple.parser.ParseException;

/**
 * Loads data from a compiled file.
 * @author G'lek
 * @version 0.0.1
 */
public class DataLoader {
    
    public static DataLibrary loadFromFile(String file) throws FileNotFoundException, IOException, ParseException{
        DataLibrary lib = new DataLibrary();
        FileInputStream fileIn = new FileInputStream(file);
        ZipInputStream zipIn = new ZipInputStream(fileIn);
        ZipEntry ent = zipIn.getNextEntry();
        while(ent != null){
            String ID = ent.getName();
            Data d = new Data(zipIn);
            lib.addDataEntry(ID, d);
            ent = zipIn.getNextEntry();
        }
        return lib;
    }
}
